//
//  SEGRedWalletPrizeView.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/3/2.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGRedWalletPrizeView.h"
@interface SEGRedWalletPrizeView ()

@property (nonatomic, retain) UIImageView* bgView;
@property (nonatomic, retain) UIImageView* titleImage;

@property (nonatomic, retain) UILabel* bottomLabel;
@property (nonatomic, retain) UIImageView* leftLine;
@property (nonatomic, retain) UIImageView* rightLine;

@end

@implementation SEGRedWalletPrizeView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self customUI];
    }
    return self;
}

#pragma mark - 初始化界面

- (void)customUI
{
//    self.backgroundColor =kColor_bg;
    
    //背景视图
    self.bgView = [[UIImageView alloc] init];
    self.bgView.userInteractionEnabled = YES;
    self.bgView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"img_hongbao_open_01")];
    [self addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.centerY.equalTo(self);
    }];
    //标题图片
    self.titleImage = [[UIImageView alloc] init];
    [self.bgView addSubview:self.titleImage];
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.bgView);
        make.top.equalTo(self.bgView);
    }];
    
    //关闭按钮
    self.closeButton = [[UIButton alloc] init];
    self.closeButton.backgroundColor = [UIColor clearColor];
    [self.closeButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_hongbao_close")] forState:UIControlStateNormal];
    [self addSubview:self.closeButton];
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker* make) {
        make.right.equalTo(self.bgView);
        make.bottom.equalTo(self.bgView.mas_top);
    }];
    
    //立即查看按钮
    self.seeSoonButton = [[UIButton alloc] init];
    self.seeSoonButton.backgroundColor = [UIColor clearColor];
    [self.seeSoonButton setTitle:@"立即查看" forState:UIControlStateNormal];
    [self.seeSoonButton setTitleColor:kColor_W forState:UIControlStateNormal];
    self.seeSoonButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.seeSoonButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_hongbao_open_01")] forState:UIControlStateNormal];
    [self.bgView addSubview:self.seeSoonButton];
    [self.seeSoonButton mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self.bgView).with.offset(15);
        make.right.equalTo(self.bgView).with.offset(-15);
        make.bottom.equalTo(self.bgView).with.offset(-15);
    }];
    
    self.bottomLabel = [[UILabel alloc] init];
    self.bottomLabel.font = [UIFont systemFontOfSize:13];
    self.bottomLabel.textColor = [UIColor colorWithRed:113/255.0 green:11/255.0 blue:7/255.0 alpha:1];;
    self.bottomLabel.backgroundColor = [UIColor clearColor];
    [self.bgView addSubview:self.bottomLabel];
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.bgView);
        make.bottom.equalTo(self.seeSoonButton.mas_top).with.offset(-15);
    }];
    
    //标题左右横线
    self.leftLine = [[UIImageView alloc] init];
    self.leftLine.image = [UIImage imageWithContentsOfFile:SEGPicName(@"img_hongbao_line_l")];
    [self.bgView addSubview:self.leftLine];
    [self.leftLine mas_makeConstraints:^(MASConstraintMaker* make) {
        make.right.equalTo(self.bottomLabel.mas_left).with.offset(-10);
        make.centerY.equalTo(self.bottomLabel.mas_centerY);
    }];
    self.rightLine = [[UIImageView alloc] init];
    self.rightLine.image = [UIImage imageWithContentsOfFile:SEGPicName(@"img_hongbao_line_r")];
    [self.bgView addSubview:self.rightLine];
    [self.rightLine mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self.bottomLabel.mas_right).with.offset(10);
        make.centerY.equalTo(self.bottomLabel.mas_centerY);
    }];
}

- (void)setViewWithDict:(NSDictionary *)data
{
    self.titleImage.image = [UIImage imageWithContentsOfFile:SEGPicName(@"img_hongbao_open_title01")];
    
    SEGAwardPrizeType prizeType = [[data objectForKey:@"prizeType"] intValue];
    switch (prizeType) {
        case kPrizeTypeProduct: // 实物
        {
            //商家名称
            UILabel *title = [[UILabel alloc] init];
            title.text = @"恭喜您获得";
            title.font = [UIFont systemFontOfSize:12];
            title.textColor = [UIColor colorWithRed:247.0/255.0 green:49/255.0 blue:33/255.0 alpha:1];
            [self.bgView addSubview:title];
            [title mas_makeConstraints:^(MASConstraintMaker* make) {
                make.centerX.equalTo(self.bgView);
                make.top.equalTo(self.bgView.mas_top).with.offset(120);
            }];
            
            //奖品名称
            UILabel *name = [[UILabel alloc] init];
            name.text = [data objectForKey:@"prizeName"];
            name.font = [UIFont systemFontOfSize:18];
            name.textColor = [UIColor colorWithRed:247.0/255.0 green:49/255.0 blue:33/255.0 alpha:1];
            [self.bgView addSubview:name];
            [name mas_makeConstraints:^(MASConstraintMaker* make) {
                make.centerX.equalTo(self.bgView);
                make.top.equalTo(title.mas_bottom).with.offset(10);
            }];
            
            self.leftLine.hidden = YES;
            self.rightLine.hidden = YES;
            self.bottomLabel.hidden = YES;
        }
            break;
        case kPrizeTypeRedWallet://现金红包
        {
            //商家名称
            UILabel *title = [[UILabel alloc] init];
            title.text = @"恭喜您获得红包";
            title.font = [UIFont systemFontOfSize:12];
            title.textColor = [UIColor colorWithRed:247.0/255.0 green:49/255.0 blue:33/255.0 alpha:1];
            [self.bgView addSubview:title];
            [title mas_makeConstraints:^(MASConstraintMaker* make) {
                make.centerX.equalTo(self.bgView);
                make.top.equalTo(self.bgView.mas_top).with.offset(120);
            }];
            
            //奖品名称
            UILabel *name = [[UILabel alloc] init];
            name.font = [UIFont systemFontOfSize:24];
            name.textColor = [UIColor colorWithRed:247.0/255.0 green:49/255.0 blue:33/255.0 alpha:1];
            [self.bgView addSubview:name];
            [name mas_makeConstraints:^(MASConstraintMaker* make) {
                make.centerX.equalTo(self.bgView);
                make.top.equalTo(title.mas_bottom).with.offset(10);
            }];
            NSMutableAttributedString* str1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@元", [NSString stringWithFormat:@"%.2f", [[data objectForKey:@"price"] floatValue] / 100]]];
            [str1 addAttribute:NSFontAttributeName
                        value:[UIFont systemFontOfSize:10]
                        range:NSMakeRange([str1 length] - 1, 1)];
            name.attributedText = str1;
            
            NSString *string = @"红包已经存入 零钱 里";
            NSMutableAttributedString* str2 = [[NSMutableAttributedString alloc] initWithString:string];
            [str2 addAttribute:NSForegroundColorAttributeName value:kColor_S2 range:NSMakeRange([str2 length] - 4, 2)];
            self.bottomLabel.attributedText = str2;
        }
            break;
        case kPrizeTypeCard: // 优惠券
        {
            //商家名称
            UILabel *title = [[UILabel alloc] init];
            title.text = [data objectForKey:@"brandName"];
            title.font = [UIFont systemFontOfSize:12];
            title.textColor = [UIColor colorWithRed:247.0/255.0 green:49/255.0 blue:33/255.0 alpha:1];
            [self.bgView addSubview:title];
            [title mas_makeConstraints:^(MASConstraintMaker* make) {
                make.centerX.equalTo(self.bgView).with.offset(10.5);
                make.top.equalTo(self.bgView.mas_top).with.offset(120);
            }];
            
            //图标
            UIImage* image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kClientImageRootURL, [data objectForKey:@"brandLogo"]]]]];
            UIImageView *icon = [[UIImageView alloc] init];
            icon.image = image;
            [self.bgView addSubview:icon];
            [icon mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(title.mas_centerY);
                make.width.height.mas_equalTo(15);
                make.right.equalTo(title.mas_left).with.offset(-6);
            }];
            
            //奖品名称
            UILabel *name = [[UILabel alloc] init];
            name.text = [data objectForKey:@"prizeName"];
            name.font = [UIFont systemFontOfSize:18];
            name.textColor = [UIColor colorWithRed:247.0/255.0 green:49/255.0 blue:33/255.0 alpha:1];
            [self.bgView addSubview:name];
            [name mas_makeConstraints:^(MASConstraintMaker* make) {
                make.centerX.equalTo(self.bgView);
                make.top.equalTo(title.mas_bottom).with.offset(10);
            }];
            
            NSString *string = @"该卡券已经存入 优惠券 里";
            NSMutableAttributedString* str = [[NSMutableAttributedString alloc] initWithString:string];
            [str addAttribute:NSForegroundColorAttributeName value:kColor_S2 range:NSMakeRange([str length] - 5, 3)];
            self.bottomLabel.attributedText = str;
        }
            break;
        default:
            break;
    }
}

//注册或认证红包
- (void)setViewWithAward:(NSString*)award prizeType:(NSString*)prizeType
{
    self.titleImage.image = [UIImage imageWithContentsOfFile:SEGPicName(@"img_hongbao_open_title02")];
    UILabel *title = [[UILabel alloc] init];
    title.text = @"恭喜您获得";
    title.font = [UIFont systemFontOfSize:12];
    title.textColor = [UIColor colorWithRed:247.0/255.0 green:49/255.0 blue:33/255.0 alpha:1];
    [self.bgView addSubview:title];
    [title mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.bgView);
        make.top.equalTo(self.bgView.mas_top).with.offset(120);
    }];
    
    //奖品名称
    UILabel *name = [[UILabel alloc] init];
    name.font = [UIFont systemFontOfSize:24];
    name.textColor = [UIColor colorWithRed:247.0/255.0 green:49/255.0 blue:33/255.0 alpha:1];
    [self.bgView addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.bgView);
        make.top.equalTo(title.mas_bottom).with.offset(10);
    }];
    name.text = award;
    
    //10：现金，20：积分
    if ([prizeType isEqualToString:@"10"]) {//现金
        NSString *string = @"红包已经存入 零钱 里";
        NSMutableAttributedString* str2 = [[NSMutableAttributedString alloc] initWithString:string];
        [str2 addAttribute:NSForegroundColorAttributeName value:kColor_S2 range:NSMakeRange([str2 length] - 4, 2)];
        self.bottomLabel.attributedText = str2;
    }else if ([prizeType isEqualToString:@"20"]) {//积分
        NSString *string = @"红包已经存入 积分 里";
        NSMutableAttributedString* str2 = [[NSMutableAttributedString alloc] initWithString:string];
        [str2 addAttribute:NSForegroundColorAttributeName value:kColor_S2 range:NSMakeRange([str2 length] - 5, 3)];
        self.bottomLabel.attributedText = str2;
    }
    
}
@end
